import React from 'react';
import { getManualGradeRuleList } from '../services';

// 没有分页
const useManualGradeRule = query => {
    const [data, setData] = React.useState([]);
    const [loading, setLoading] = React.useState(false);
    const [error, setError] = React.useState(null);

    const fetchData = async () => {
        setLoading(true);
        const { data: rawData, code, msg } = (await getManualGradeRuleList(query)) || {};
        if (code === 10000) {
            setData(rawData);
        } else {
            setError(msg);
        }
        setLoading(false);
    };

    React.useEffect(() => {
        fetchData();
    }, [JSON.stringify(query)]);

    return [loading, data, fetchData, error];
};

export default useManualGradeRule;
